package cn.itsource.basic.util;

import cn.hutool.core.lang.RegexPool;
import cn.hutool.core.lang.Validator;
import cn.hutool.core.util.PhoneUtil;

import java.util.regex.Pattern;

/**
 * @author: maizi
 * @Description:
 * @Date: Created in 15:45 2022/2/25
 * @Modified: By:
 */
public class MyValidateUtil {

    public static void matchesPhone(String phone){
        //  Validator.validateMobile () 糊涂自带的工具类验证
        //校验手机号
        if(!Pattern.matches (RegexPool.MOBILE,phone)) throw new RuntimeException ("手机号格式有误,请确认后重新输入");
    }
    //测试糊涂工具类的手机号校验
    public static void main (String[] args) {
        //1.jdk1.8自带的正则校验工具类------------------------------
        String phone = "12271799569";
        boolean matches = Pattern.matches (RegexPool.MOBILE, phone);
        //2.String 的正则校验匹配-------------------------------------
        boolean matches1 = phone.matches (RegexPool.MOBILE);
        System.out.println ("matches = " + matches);
        //3.糊涂工具类的手机号校验-------------------------------------
        Validator.validateMobile ("12571799568","手机号格式有误,请确认后重新输入");
        //4.糊涂工具类的手机号正则匹配-------------------------------------
        boolean phone1 = PhoneUtil.isPhone("13355557777");
        if (!phone1) throw new RuntimeException("");
        //5.自己写的手机号校验工具类------------------------------------
        MyValidateUtil.matchesPhone (phone);
    }

}
